package com.hdd.art.biz.show.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.show.entity.Showroom;
import com.hdd.art.biz.show.entity.ShowroomRule;
import com.hdd.art.biz.show.entity.ShowroomScreen;
import com.hdd.art.biz.show.mapper.ShowroomMapper;
import com.hdd.art.biz.show.service.ShowroomRuleService;
import com.hdd.art.biz.show.service.ShowroomScreenService;
import com.hdd.art.biz.show.service.ShowroomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;
import java.util.List;

/**
 * <p>
 * 展厅 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-06-27
 */
@Service
public class ShowroomServiceImpl extends ServiceImpl<ShowroomMapper, Showroom> implements ShowroomService {


    @Autowired
    private ShowroomScreenService showroomScreenService;
    @Autowired
    private ShowroomRuleService showroomRuleService;

    @Override
    public List<Showroom> findShowroomByArtId(String artId) {
        QueryWrapper<Showroom> wrapper = new QueryWrapper<>();
        wrapper.eq("art_id",artId);
        wrapper.orderByDesc("create_time");
        return baseMapper.selectList(wrapper);
    }

    @Override
    public void addShowRoom(Showroom showroom) {
        baseMapper.insert(showroom);
        ShowroomScreen screen = new ShowroomScreen();
        screen.setRoomId(showroom.getId());
        screen.setImgUrl(showroom.getIconUrl());
        screen.setArtId(showroom.getArtId());
        screen.setDef("T");
        showroomScreenService.addShowRoomScreen(screen);

        ShowroomRule showroomRule = new ShowroomRule();
        showroomRule.setRoomId(screen.getRoomId());
        showroomRuleService.addRule(showroomRule);
    }

    @Override
    public void updateShowRoom(Showroom showroom,Integer fontCoverId) {
        baseMapper.updateById(showroom);

        showroomScreenService.setDef(showroom.getId(),fontCoverId);
    }

    @Override
    public void delShowRoomById(Integer id) {
        baseMapper.deleteById(id);
    }
}
